<form name="frmsearch" id="frmsearch" action="<?php echo base_url()?>orders/listorders" method="post">
  <table class="frmsearch" width="100%" cellspacing="5px" style="background: #ffefdd; color:#000; margin:0px 0px 10px; padding:10px; height:120px">            
                <tbody>
                    <tr>
                        <td><label class="lb">Tên khách hàng:</label><input type="text"  name="fullname" id="orderdate" value="<?php if(isset($fullname)) echo $fullname?>"></td>
                         <td><label class="lb">Từ ngày đặt:</label><input type="text" name="tu_ngay" id="datepicker" value="<?php if(isset($tu_ngay)) echo $tu_ngay?>"></td>     
                        <td><label class="lb">Tỉnh/Thành Phố:</label>
                        <select id="city_id" name="city_id" >
                            <option value=""> Chọn Tỉnh/Thành phố</option>
                            <?php echo $option_pid ?>
                        </select>
               			</td>
                                          
                    </tr>
                    <tr>
                        <td><label class="lb">Mã đơn hàng:</label><input type="text" class="l4" name="order_id" id="order_id" value="<?php if(isset($order_id)) echo $order_id?>"></td>
                         <td><label class="lb">Đến ngày đặt:</label><input type="text" name="den_ngay" id="datepicker_order" value="<?php if(isset($den_ngay)) echo $den_ngay?>"></td>   
                        <td><label class="lb">Quận/Huyện:</label>
                            <select id="district_id" name="district_id" >
                                <option value=""> Chọn Quận/Huyện</option>
                                 <?php echo $option_district?>
                            </select>
               			</td>
                                                 
                                                                        
                    </tr>
                    <tr>                        
                        <td><label class="lb">Điện thoại:</label><input type="text" class="l4" name="phone" id="phone" value="<?php if(isset($phone)) echo $phone?>"></td>
                          <td><label class="lb" title="Tình trạng">Tình trạng:</label>
                                    <?php echo $option_status?>
                        </td>   
                        <td align="right"><input type="submit" id="ordersearch" name="ordersearch" value="Tìm đơn hàng"></td>                             
                    </tr>
                    
                </tbody>
            </table>
 </form>
<?php $attributes = array('class' => 'email', 'id' => 'checknew');
echo form_open('products/dels', $attributes);?>    

<input type="hidden" name="page" value="<?php echo (int)$this->uri->segment('3')?>">

        <table class="admindata">
            <thead>
                <tr>
                    <th colspan="12">
                           <!-- <input type="submit" onclick="return verify_del();" name="btn_submit" class="submit" value="Xóa">-->
                        Hiện có <?php echo $num?> đơn hàng
                        <div class="fr">
                           <!-- <a href="<?php echo site_url('products/add')?>">Thêm mới</a> -->
                        </div>
                    </th>
                </tr>
                <tr class="head_tb">
                    <th class="checkbox"><input type="checkbox" name="sa" id="sa" onclick="check_chose('sa', 'ar_id[]', 'checknew')" /></th>
                    <th width="40" style="text-align:center">STT</th>
                    <th width="100" style="text-align:center">Mã đơn hàng</th>
                    <th width="">Khách hàng</th>
                    <th width="">Địa chỉ</th>
                    <th width="">Điện thoại</th>
                    <th width="">Ngày đặt</th>
                     <th width="">Tổng tiền</th>
                    <th class="publish" style="width: 200px;">Trạng thái</th>
                </tr>                
            </thead>
            <?
            $k=1;$i=1; $tongtien_order=0;
            foreach($list as $rs):?>
            <tr class="row<?php echo $k?>">
                <td><input type="checkbox" name="ar_id[]" value="<?php echo $rs->order_id ?>"></td>
               
                 <td style="text-align:center"><?php echo $i;?></td>
                  <td style="text-align:center"><?php echo $rs->order_id?></td>
                   <td>
                   <?php echo $rs->fullname?>
                </td>
                <td>
                  <?php echo $rs->address.', '.$rs->district_name.', '.$rs->city_name; ?>
                </td>
                 <td>
                   <?php echo $rs->phone?>
                </td>
                 
                
                 <td>
                    <?php echo $rs->dt_create?>
                </td>
                <td>
                   
                   <?php echo number_format($rs->total_order, 0, ',', '.')?>
                </td>
                <td align="center">
                <?php if($this->acl->check('edit','mod_orders','orders')){ ?> 
                    <?php echo icon_edit('orders/edit/'.$rs->order_id)?>
                  <?php } ?> 
                   <?php if($this->acl->check('del','mod_orders','orders')){ ?> 
                    <?php echo icon_del('orders/del/'.$rs->order_id.'/'.(int)$this->uri->segment(4))?>
                 <?php } ?>
                  <a href="<?php echo base_url()?>orders/print_order/<?php echo $rs->order_id ?>" title="In đơn hàng" target="_blank"><img src="<?php echo base_url()?>templates/images/printer.png" width="20" height="20"></a>
                 	<a href="<?php echo base_url()?>orders/load_order_product/<?php echo $rs->order_id ?>" title="Sản phẩm của đơn hàng"  id="addimages" class="cboxElement"><img src="<?php echo base_url()?>templates/icon/cart.png" width="22" height="22"></a>
                  <?php if(($this->session->userdata('group_id') == 5) && ($rs->bl_approve ==0)) {
					  		if($this->acl->check('del','mod_orders','orders') ){ 	
								 echo $this->string_library->optionStatus($rs->bl_active);
							}
				  		}else if($this->session->userdata('group_id') == 1 || $this->session->userdata('group_id') == 4){
								if($this->acl->check('del','mod_orders','orders') ){ 	
								 	echo $this->string_library->optionStatus($rs->bl_active);
								}
						}else{
							if(($this->session->userdata('group_id') == 5) && ($rs->bl_approve ==1)){
								if($this->acl->check('del','mod_orders','orders') ){ 	
										echo $this->string_library->optionStatus($rs->bl_active,'disabled');
								}
							}
						}
				  ?> 
                    <input type="hidden" value="<?php echo $rs->order_id?>" name="order_id" />
                </td>
            </tr>
            <?
			$tongtien_order +=$rs->total_order;
			$i++;
            $k=1-$k;
            endforeach;?>
            <tfoot>
                <td colspan="12" style="padding-top:10px; padding-bottom:10px; ">
                       <!-- <input type="submit" onclick="return verify_del();" name="btn_submit" class="submit" value="Xóa">-->
                    Hiện có <?php echo $num?>  đơn hàng  <span class="page_click"> <?php echo $pagination?></span>
                    <div style=" float:right;text-align:right; font-size:16px; color:#F00; font-weight:bold; "><span>Tổng tiền : </span>  <?php echo number_format($tongtien_order, 0, ',', '.')?> VNĐ</div>
                </td>
            </tfoot>
        </table>  
<?php echo form_close()?>  
<script type="text/javascript">
	$(document).ready(function(){
		$( ".page_click a" ).click(function() {
		  var page_url = $(this).attr('href');
		  $('#frmsearch').attr('action',page_url);
		  $('#frmsearch').submit();
		  return false;
		});
		$("#city_id").change(function(){
		 var city_id=$(this).val();
		 $.ajax({
		   type : 'POST',
		   url : "<?php echo base_url()?>orders/option_district/" + city_id,
		   data: {city_id:city_id},
		   dataType: "html",
		   success : function(data){
			 $("#district_id").html(data);
		   }
		 })
		});
		
		$(".cbo_trangthai").change(function(){
			var cboTrangThai = $(this);
		 	var bl_active = cboTrangThai.val();
		 	var orderId = cboTrangThai.parent('td').find("input[name=order_id]").val();
		 $.ajax({
		   type : 'POST',
		   url : "<?php echo base_url()?>orders/update_active/" + bl_active,
		   data: {bl_active:bl_active,order_id:orderId},
		   dataType: "json",
		   success : function(data){
			if(data.status==true){
				alert(data.message);
				window.location.reload();
			}else if(data.status==false){
				alert(data.message);
				window.location.reload();
			}
			
		   }
		 })
		});
	});
 
</script>
<script>
  $(function() {
    $( "#datepicker" ).datepicker({
      changeMonth: true,
      changeYear: true
    });
	$( "#datepicker" ).datepicker( "option", "dateFormat",'yy-mm-dd' );
  });
  </script>
  <script>
  $(function() {
    $( "#datepicker_order" ).datepicker({
      changeMonth: true,
      changeYear: true
    });
	$( "#datepicker_order" ).datepicker( "option", "dateFormat",'yy-mm-dd' );
  });
  </script>
  <script type="text/javascript">
$().ready(function() {
	<!-- CÁCH 2 SỬ DỤNG KEYPRESS CỦA JQUERY -->
	$('#phone').yamFormat({type : 'int'});
})
</script>
